#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cstdbool>
#include<queue>
#include <utility>
#include<stack>
#include<iostream>
using namespace std;

class Solution
{
public:
    int h[10], ne[10], e[10], idx = 0;
    bool st[10];

    void add(int a, int b)
    {
        e[idx] = b, ne[idx] = h[a], h[a] = idx++;
    }
    int numOfMinutes(int n, int hID, vector<int>& me, vector<int>& it)
    {
        int ans = 0;
        vector<bool> st(n, false);
        unordered_map<int, vector<int>> hash;
        for (int i = 0; i < n; i++)
            hash[me[i]].push_back(i);

        queue<int> q;
        q.push(hID);
        st[hID] = true;
        while (!q.empty())
        {
            int tmp = q.front();
            ans += it[tmp];
            int sz = q.size();
            for (int j = 0; j < sz; j++)
            {
                int t = q.front();
                q.pop();
                for (int i = 0; i < hash[t].size(); i++)
                {
                    int j = hash[t][i];
                    if (!st[j])
                    {
                        q.push(j);
                        st[j] = true;
                    }
                }
            }
            
            
        }
        return ans;
    }
};

int main()
{
    Solution A;
    vector<int> nums({ -1,5,0,6,7,0,0,0 });
    vector<int> nums1({ 89,0,0,0,0,523,241,519 });

    vector<string> s({ "lc","cl","gg" });
    A.numOfMinutes(8, 0, nums, nums1);


   
    return 0;
}
